{extend name="base" /}
<!-- page specific plugin styles -->
{block name="plugin-styles"}{/block}
<!-- inline styles related to this page -->
{block name="inline-styles"}{/block}
<!-- breadcrumb -->
{block name="breadcrumbs"}
<ul class="breadcrumb">
    <li>
        <i class="ace-icon fa fa-home home-icon"></i>
        <a href="{:url('Index/index')}">首页</a>
    </li>
    <li class="active">虚拟币管理</li>
</ul>
<!-- /.breadcrumb -->
{/block}
<!-- PAGE CONTENT BEGINS -->
{block name="content"}
<div class="page-header">
    <h1>
        提现记录
    </h1>
</div>
<!-- /.page-header -->
<div class="clearfix tableTools-container">
    <form class="pull-left form-inline">
        <input type="hidden" class="form-control input-sm" name="mid" value='{$mid}' >
        <div class="form-group">
            <label class="sr-only" for="goodsname">代理名称</label>
            <div class="input-group">
                <span class="input-group-addon">代理名称</span>
                <input type="text" class="form-control input-sm" name="name" placeholder="代理姓名或手机号">
            </div>
        </div>
        <div class="form-group">
            <label class="control-label" for="isshow">状态</label>
            <select class="form-control input-sm" name="status" id="">
                <option value="">全部</option>
                <option value="0">待审核</option>
                <option value="1">已通过</option>
                <option value="2">未通过</option>
            </select>
        </div>
        <div class="form-group">
            <button  type="button" class="btn btn-xs btn-primary" id="searchTable">搜索</button>
            <button type="reset" class="btn btn-xs btn-primary" >重置</button>
        </div>
    </form>
</div>
<div class="table-responsive">
    <table class="table table-bordered" id="DynamicTable"></table>
</div>
<!-- /.table-responsive -->

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header no-padding">
                <div class="table-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    审核备注
                </div>
            </div>
            <div class="modal-body">
                <textarea class="form-control" id="remark"></textarea>
            </div>
            <div class="modal-footer">
                <button class="btn btn-sm btn-success pull-right" onClick="examine()"> <i class="ace-icon fa fa-check"></i> 保存 </button>
                <button class="btn btn-sm btn-danger pull-right" data-dismiss="modal"> <i class="ace-icon fa fa-times"></i> 取消 </button>
            </div>
        </div>
    </div>
</div>

{/block}
<!-- PAGE CONTENT ENDS -->
<!-- page specific plugin scripts -->
{block name="plugin-scripts"}
<script src="/static/ace/assets/js/jquery.dataTables.min.js"></script>
<script src="/static/ace/assets/js/jquery.dataTables.bootstrap.min.js"></script>
{/block}
<!-- inline scripts related to this page -->
{block name="related-scripts"}
<script type="text/javascript">
var myTable
    jQuery(function($) {
    	myTable = 
        $('#DynamicTable')
        .wrap("<div class='dataTables_borderWrap' />")   //if you are applying horizontal scrolling (sScrollX)
        .DataTable({
            "autoWidth": false, //智能列宽处理
            "deferRender": true,    //延迟渲染以获得额外的初始化速度
            "info": true,   //表信息显示
            "lengthChange": false,  //更改每页记录数
            "ordering": false,  //排序功能
            "paging": true, //启用或禁用表分页
            "processing": false,    //处理指标
            // "scrollX": false,    //水平滚动
            // "scrollY": false,    //垂直滚动
            "searching": false, //搜索功能
            "serverSide": true, //服务器端处理模式
            "stateSave": false, //状态保存(页面重新加载时恢复表状态)
            "language": {
                "url": "//cdn.datatables.net/plug-ins/1.10.19/i18n/Chinese.json"
            },
            "ajax": {
                "url": "/admin/withdraw/all_rs",
                "type": "Post",
                "data": function (d) {
                    d.status = $("select[name=status]").val();
                    d.start_date = $("input[name=start_date]").val();
                    d.end_date = $("input[name=end_date]").val();
                    // d.isshow = $("select[name=isshow]").val();
                    d.name = $("input[name=name]").val();
                    d.mid = $("input[name=mid]").val();
                },
                "dataSrc": function (json) {
                    return json.data;
                }
            },
            "columns": [{
                "title": "ID",
                "data": "id"
            }, {
                "title": "代理名称",
                "data": "name"
            }, {
                "title": "提现金额",
                "data": "money"
            }, {
                "title": "账户类型",
                "data": "paytype_name",
            }, {
                "title": "账户信息",
                "data": "",
            },{
                "title": "备注",
                "data": "remark"
            },{
                "title": "状态",
                "data": "status_name"
            }, {
                "title": "申请时间",
                "data": "ctime"
            }, {
                "title": "操作",
                "data": "id"
            }],
            "columnDefs": [{
                "className": "text-center",
                "targets": [0,1,2,3,4]
            },{
                "render": function (data, type, row, meta) {
                    return '<a href="{:url('agent/detail')}?mid='+row.mid+'" target="  _blank">'+row.name+'</a>';;
                },
                "targets": 1  
            },{
                "render": function (data, type, row, meta) {
                    return row.addr+" , "+row.bank_name+' , '+row.num;
                },
                "targets":4
            },  {
                "render": function (data, type, row, meta) {
                    if(row.status == 1){
                        return '<span class="label label-success">'+row.status_name+'</span>';;
                    }else if(row.status == 2){
                        return '<span class="label label-danger">'+row.status_name+'</span>';;
                    }else{
                        return '<span class="label label-warning">'+row.status_name+'</span>';;
                    }
                },
                "targets": 6
            },{
                "render": function (data, type, row, meta) {
                    if(row.status == 0){
                        
                        return '<div class="btn-group">\
                            <button data-toggle="modal" data-target="#myModal" class="btn btn-xs btn-success" data-rel="tooltip" title="通过" onClick="showModal('+data+',1)">\
                                <i class="ace-icon fa fa-check bigger-120"></i>\
                            </button>\
                            <button data-toggle="modal" data-target="#myModal" class="btn btn-xs btn-danger" data-rel="tooltip" title="不通过" onClick="showModal('+data+',2)">\
                                <i class="ace-icon fa fa-times bigger-120"></i>\
                            </button>\
                        </div>';
                    }else {
                       return ''
                    }
                },
                "targets": 8
            }],
            "initComplete": function( settings, json ) {
                $("#DynamicTable").prev(".row").remove();
                //add tooltip for small view
                $('[data-rel="tooltip"]').tooltip();
            }
        });
    	
    	$("#searchTable").click(function () {
            myTable.draw();
        });
    });
    
// 查看
function showModal(_id, _status){
    $("#myModal").data("id",_id);
    $("#myModal").data("status",_status);
}
// 审核
function examine(){
    if($("#myModal").data("status")==1){
        var _url = "/admin/withdraw/pass";
    }else{
        var _url = "/admin/withdraw/unpass";
    }
    $.ajax({
        url: _url,
        type: 'POST',
        dataType: 'json',
        data: {
            id: $("#myModal").data("id"),
            remark: $("#remark").val()
        },
    })
    .done(function(json) {
        console.log("success");
        alert(json.returnMsg);
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });
    
}
</script>
{/block}